package haiyangwangwork.day10.第一组.杨琳;

import java.util.Scanner;


public class Demo5 {
//    输入5个同学的姓名和成绩，求出最高分，最低分和平均分，以及每个人的成绩与平均分的差值。
//    最后，按分数从高到低排序。
public static void main(String[] args) {
    Scanner input = new Scanner(System.in);

    double  sum=0;
    String[] studentName = new String[5];
    double[] studentGrade = new double[5];
    for (int i =0;i < studentName.length;i++){
        System.out.println("请输入学生姓名：");
        studentName[i]= input.next();
        System.out.println("请输入学生成绩：");
        studentGrade[i]=input.nextDouble();
        sum+=studentGrade[i];

    }
//    对学生成绩数组进行排序
    for (int i = 0;i < studentGrade.length-1;i++){//外层循环控制轮数
        for (int j = 0;j < studentGrade.length-1-i;j++){//控制具体的比较次数
            //这里面控制两个数相比较
            if (studentGrade[j]<studentGrade[j+1]){//谁小谁往右摆放
                double temp;
                temp=studentGrade[j];
                studentGrade[j]=studentGrade[j+1];
                studentGrade[j+1]=temp;
                //姓名绑定成绩
                String name =studentName[j];
                studentName[j]=studentName[j+1];
                studentName[j+1]=name;

            }
        }
    }
    //最大值
    double max = studentGrade[0];
    //最小值
    double min = studentGrade[studentGrade.length-1];
    //平均分
    double average =sum/studentGrade.length;
//    int sum = studentGrade[0]+studentGrade[1]+studentGrade[2]+studentGrade[3]+studentGrade[4];


    for (int i = 0;i< studentName.length;i++){

        System.out.println("学生姓名"+studentName[i]+" 学生成绩"+studentGrade[i]+"成绩与平均分的差值"+(studentGrade[i]-average));
    }
    System.out.println("最大值"+max);
    System.out.println("最小值"+min);
}
}
